package Frontend

import (
	"fmt"
	"net/http"
)

type admin_user struct {
	Id int `db:"id"json:"id"`
	Username string `db:"username"json:"username"`
	Password string `db:"password"json:"password"`
}
// 用于判断用户登录作用
func Admin_bm_login(w http.ResponseWriter, r *http.Request)  {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	username:=r.PostFormValue("username")
	password:=r.PostFormValue("password")
	fmt.Println("username=",username)
	fmt.Println("password=",password)
	sqlStr := "select * from admin_user where username=? and password=?"
	var u = struct {
		Id int `db:"id"json:"id"`
		Username string `db:"username"json:"username"`
		Password string `db:"password"json:"password"`
	}{}
	err := db.Get(&u, sqlStr, username,password)
	if err != nil {
		fmt.Println("get failed, err:%v\n", err)
		jsonk := `{"isok":"no","msg":"不存在用户"}`
		fmt.Println("返回前台数据为：", jsonk)
		w.Write([]byte(jsonk)) //给客户端返回数据。
		return
	}
	fmt.Println("获取数据库：", u)
	jsonk := `{"isok":"ok","msg":"登录"}`
	fmt.Println("返回前台数据为：", jsonk)
	w.Write([]byte(jsonk)) //给客户端返回数据。
}